<template>
  <div class="app-container">
    <el-card class="search-card">
      <el-form size="small" ref="queryForm" :model="queryParams" class="formBox" label-width="88px">
        <el-row :gutter="0">
          <el-col :span="5">
            <el-form-item label="银行名称" prop="name">
              <el-input
                v-model="queryParams.name"
                placeholder="请输入学校名称"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="启用状态" prop="status" class="width_100">
              <el-select
                v-model="queryParams.status"
                placeholder="请选择启用状态"
                clearable
                style="width: 100%"
              >
                <el-option
                  v-for="dict in dict.type.sys_open_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="14">
            <el-form-item>
              <div class="dis aic">
                <div class="flex_1"></div>
                <el-button
                  type="primary"
                  icon="el-icon-search"
                  size="mini"
                  @click="handleQuery"
                >
                  搜索
                </el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">
                  重置
                </el-button>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>

    <el-card class="table-card">
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['campus:school:add']"
            >新增</el-button
          >
        </el-col>
        <right-toolbar
          :showSearch.sync="showSearch"
          @queryTable="banksListFun"
        ></right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="schoolList">
        <el-table-column label="银行名称" align="center" prop="name" />
        <el-table-column label="银行CODE" align="center" prop="code" />
        <el-table-column label="银行bankNum" align="center" prop="bankNum" />
        <el-table-column label="启用状态" align="center" prop="status">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.status == 1">启用</el-tag>
            <el-tag type="danger" v-if="scope.row.status == 0">禁用</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="创建时间" align="center" prop="createdAt" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d} {h}:{i}:{s}") }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['campus:school:edit']"
              >修改</el-button
            >
            <!-- <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['campus:school:remove']"
              >删除
              </el-button> -->
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="banksListFun"
      />
    </el-card>

    <!-- 添加或修改学校列表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="40%" append-to-body>
      <el-form ref="form" :model="form" label-width="180px">
        <el-row>
          <el-col :span="20">
            <el-form-item label="银行名称" class="is-required">
              <el-input
                v-model="form.name"
                placeholder="请输入银行名称"
                maxlength="50"
                show-word-limit
              />
            </el-form-item>
            <el-form-item label="银行CODE" class="is-required">
              <el-input
                v-model="form.code"
                placeholder="请输入银行CODE"
                maxlength="50"
                show-word-limit
              />
            </el-form-item>
            <el-form-item label="银行bankNum" class="is-required">
              <el-input
                v-model="form.bankNum"
                placeholder="请输入银行bankNum"
                maxlength="50"
                show-word-limit
              />
            </el-form-item>

            <el-form-item label="启用状态" prop="status">
              <el-radio-group v-model="form.status">
                <el-radio
                  v-for="dict in dict.type.sys_open_status"
                  :key="dict.value"
                  :label="dict.value"
                  >{{ dict.label }}</el-radio
                >
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { banksList, banksDetail, banksAdd, banksUpdate } from "@/api/bank/index";

export default {
  name: "bank",
  dicts: ["sys_open_status", "grade"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 学校列表表格数据
      schoolList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        status: null,
      },
      // 表单参数
      form: {},
      provinceList: [],
      cityList: [],
      districtList: [],
      // 银行
      getbankList: [],
    };
  },
  created() {
    this.banksListFun();
  },
  activated() {
    this.$forceUpdate();
  },
  methods: {
    /** 查询学校列表列表 */
    banksListFun() {
      this.loading = true;
      banksList(this.queryParams).then((response) => {
        this.schoolList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        status: null,
        address: null,
        contactPerson: null,
        contactPhone: null,
        createdAt: null,
        grades: [],
        schoolIntro: null,
        schoolLogo: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.banksListFun();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加银行";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id;
      banksDetail(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改银行";
      });
    },
    /** 提交按钮 */
    submitForm() {
      var that = this;
      this.$refs["form"].validate((valid) => {
        if (this.form.id != null) {
          banksUpdate(this.form).then((response) => {
            that.$modal.msgSuccess("修改成功");
            that.open = false;
            that.banksListFun();
          });
        } else {
          banksAdd(that.form).then((response) => {
            that.$modal.msgSuccess("新增成功");
            that.open = false;
            that.banksListFun();
          });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      // const ids = row.id ;
      // this.$modal
      //   .confirm('是否确认删除学校列表编号为"' + ids + '"的数据项？')
      //   .then(function () {
      //     return delSchool(ids);
      //   })
      //   .then(() => {
      //     this.banksListFun();
      //     this.$modal.msgSuccess("删除成功");
      //   })
      //   .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "campus/school/export",
        {
          ...this.queryParams,
        },
        `school_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style>
.el-upload--picture-card {
  width: 90px !important;
  height: 90px !important;
  line-height: 90px !important;
}

.width_100 {
  width: 100% !important;
}
.display_flex {
  display: flex !important;
}
</style>
